package com.spic.business.train.experience.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.spic.common.core.utils.SecurityUtils;
import com.spic.common.core.utils.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.business.train.experience.domain.TrainExperience;
import com.spic.business.train.experience.service.ITrainExperienceService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.page.TableDataInfo;

/**
 * 心得体会Controller
 * 
 * @author spic
 * @date 2021-10-21
 */
@RestController
@RequestMapping("/train/experience")
public class TrainExperienceController extends BaseController
{
    @Autowired
    private ITrainExperienceService trainExperienceService;

    /**
     * 查询心得体会列表
     */
    @PreAuthorize(hasPermi = "business/train:experience:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainExperience trainExperience)
    {
        startPage();
        List<TrainExperience> list = trainExperienceService.selectTrainExperienceList(trainExperience);
        return getDataTable(list);
    }

    /**
     * 导出心得体会列表
     */
    @PreAuthorize(hasPermi = "business/train:experience:export")
    @Log(title = "心得体会", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainExperience trainExperience) throws IOException
    {
        List<TrainExperience> list = trainExperienceService.selectTrainExperienceList(trainExperience);
        ExcelUtil<TrainExperience> util = new ExcelUtil<TrainExperience>(TrainExperience.class);
        util.exportExcel(response, list, "心得体会数据");
    }

    /**
     * 获取心得体会详细信息
     */
    @PreAuthorize(hasPermi = "business/train:experience:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(trainExperienceService.selectTrainExperienceById(id));
    }

    /**
     * 新增心得体会
     */
    @PreAuthorize(hasPermi = "business/train:experience:add")
    @Log(title = "心得体会", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainExperience trainExperience)
    {
        trainExperience.setId(UUIDUtil.createUUID());
        trainExperience.setCreateBy(String.valueOf(SecurityUtils.getUserId()));

        return toAjax(trainExperienceService.insertTrainExperience(trainExperience));
    }

    /**
     * 修改心得体会
     */
    @PreAuthorize(hasPermi = "business/train:experience:edit")
    @Log(title = "心得体会", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainExperience trainExperience)
    {
        return toAjax(trainExperienceService.updateTrainExperience(trainExperience));
    }

    /**
     * 删除心得体会
     */
    @PreAuthorize(hasPermi = "business/train:experience:remove")
    @Log(title = "心得体会", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(trainExperienceService.deleteTrainExperienceByIds(ids));
    }
}
